<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">

            <h2 class="title">Pesquisar Imóvel</h2><br/>
            <p:growl id="messages" showDetail="false" autoUpdate="true"  /> 

            <h:form id="userForm" style="margin: 0 30px;" enctype="multipart/form-data">
                <h4 class="title">Fator Localização</h4>

                <p:panel id="fatorPanel" 
                         styleClass="container_24 clearfix">

                    <p:outputLabel value="Inscrição Imóvel" styleClass="grid_4 inscricaoLabelImovel" 
                                   for="maskinscricao" rendered="false"/>
                    <p:inputMask mask="?**.**.***.****.**" id="maskinscricao" rendered="false"
                                 styleClass="grid_6"  value="#{managerPesquisarImovel.visaoInscricao}"/>
                    <p:watermark value="DD.SS.QUADR.LOTE.UN" for="maskinscricao" />

                    <div class="clear"/>
                    <p:outputLabel value="Distrito" styleClass="grid_3" for="dInput"/>
                    <p:inputText id="dInput" styleClass="grid_4" 
                                 value="#{managerPesquisarImovel.imovel.inscricaoCadastralD}" />

                    <p:outputLabel value="Setor" styleClass="grid_3" for="sInput"/>
                    <p:inputText id="sInput" styleClass="grid_4" 
                                 value="#{managerPesquisarImovel.imovel.inscricaoCadastralS}" />

                    <p:outputLabel value="Quadra" styleClass="grid_3" for="qInput"/>
                    <p:inputText id="qInput" styleClass="grid_4" 
                                 value="#{managerPesquisarImovel.imovel.inscricaoCadastralQuadra}"/>
                    <div class="clear-both" />

                    <p:outputLabel value="Lote" styleClass="grid_3" for="lInput"/>
                    <p:inputText id="lInput" styleClass="grid_4" 
                                 value="#{managerPesquisarImovel.imovel.inscricaoCadastralLote}"/>

                    <p:outputLabel value="Unidade" styleClass="grid_3" for="uInput"/>
                    <p:inputText id="uInput" styleClass="grid_4" 
                                 value="#{managerPesquisarImovel.imovel.inscricaoCadastralUnid}"/>
                    <div class="clear-both" />
                </p:panel>

                <h4 class="title">Proprietário</h4>

                <p:panel id="ownerPanel" 
                         styleClass="container_24 clearfix">
                    <p:outputLabel value="Proprietário" styleClass="grid_3 proprietarioLabelPesquisar"/>
                    <p:selectOneRadio id="typePerson" 
                                      value="#{managerPesquisarImovel.proprietario.tipoDocumento}" >  
                        <f:selectItems value="#{managerUtilitario.tipoDocumento}" />
                        <p:ajax event="change" update=":userForm:ownerPanel" />
                    </p:selectOneRadio>

                    <div class="clear"/>

                    <p:outputLabel id="typeDocumentLabel" 
                                   value="#{managerPesquisarImovel.proprietario.tipoDocumento}: " 
                                   styleClass="grid_3"/>

                    <f:validateBean disabled="true">
                        <p:inputMask id="typeDocumentInput" 
                                     value="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CPF' ? 
                                              managerPesquisarImovel.proprietario.cpf : managerPesquisarImovel.proprietario.cnpj}"
                                     mask="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CPF' ? 
                                             '999.999.999-99':'99.999.999/9999-99'}" 
                                     styleClass="grid_5" > 

                        </p:inputMask>
                    </f:validateBean>
                    <div class="clear"/>
                    <p:outputLabel value="Nome: " styleClass="grid_3" for="nomeInputText" 
                                   rendered="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CPF'}"/>
                    <p:inputText id="nomeInputText" styleClass="grid_19" 
                                 value="#{managerPesquisarImovel.proprietario.nome}" 
                                 rendered="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CPF'}" />

                    <p:outputLabel value="Fantasia: " styleClass="grid_3" for="nameFantasyInputText" 
                                   rendered="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CNPJ'}" />
                    <p:inputText id="nameFantasyInputText" styleClass="grid_19"
                                 value="#{managerPesquisarImovel.proprietario.nomeFantasia}" 
                                 rendered="#{managerPesquisarImovel.proprietario.tipoDocumento.tipo eq 'CNPJ'}" />

                </p:panel>

                <h4 class="title">Endereço</h4>

                <p:panel id="addressPanel" 
                         styleClass="container_24 clearfix ">
                    <p:outputLabel value="CEP" styleClass="grid_3" for="cepInputMask" />
                    <p:inputMask id="cepInputMask" styleClass="grid_4" mask="99.999-999"
                                 value="#{managerPesquisarImovel.endereco.cep}" />
                    <div class="clear-both" />

                    <p:outputLabel value="Número" styleClass="grid_3" for="numInputText" />
                    <p:inputText id="numInputText" styleClass="grid_2"
                                 value="#{managerPesquisarImovel.endereco.numero}" />

                    <p:outputLabel value="Logradouro" styleClass="grid_4 alpha" for="patioInputText" />
                    <p:inputText id="patioInputText" styleClass="grid_13"
                                 value="#{managerPesquisarImovel.endereco.logradouro}" />

                    <div class="clear-both" />
                    <p:outputLabel value="Bairro" styleClass="grid_3" for="neighborhoodInputText" />
                    <p:inputText id="neighborhoodInputText" styleClass="grid_19"
                                 value="#{managerPesquisarImovel.endereco.bairro}" />

                </p:panel>

                <br/>
                <div class="buttonAction">
                    <p:commandButton id="pesquisarCommandButton" value="Pesquisar" icon="ui-icon-search"
                                     update="tableImovel"
                                     actionListener="#{managerPesquisarImovel.pesquisarImovel()}"
                                     styleClass="ui-priority-primary" />
                    <p:commandButton id="bt_clear" value="Limpar" icon="ui-icon-clean"
                                     actionListener="#{managerPesquisarImovel.limpar()}"
                                     update="@form" process="@this" />
                </div >
                <br/><br/>

                <p:blockUI id="BLOCK" block="resultPanel" trigger="pesquisarCommandButton, tableImovel" > 
                    <p:graphicImage value="media/images/ajax-loader.gif"/>
                </p:blockUI> 

                <h4 class="title">Resultado</h4>
                <p:panel id="resultPanel" 
                         styleClass="container_24 clearfix ">

                    <p:dataTable id="tableImovel" var="item" value="#{managerPesquisarImovel.dataModel}"
                                 styleClass="grid_24" rowIndexVar="rowid" 
                                 style="white-space: pre-wrap;" 
                                 binding="#{managerPesquisarImovel.searchResults}"
                                 rows="5" paginator="true" lazy="true"
                                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                                 currentPageReportTemplate="{currentPage} de {totalPages}"
                                 paginatorPosition="bottom" emptyMessage="Nenhum registro">

                        <f:facet name="header">
                            <p:outputLabel value="Imóvel #{managerPesquisarImovel.searchResults.rowCount eq 0 ? '' : '('.concat(managerPesquisarImovel.searchResults.rowCount).concat(')')}" />
                        </f:facet>
                        <p:column headerText="Ação" width="120">
                            
                            <p:commandButton value="Emitir" update="@form" 
                                        actionListener="#{managerPesquisarImovel.validaConfigItbi(item)}"
                                        icon="ui-icon-arrowrefresh-1-w"/> 
                           
                            
                           
                        </p:column>

                        <p:column headerText="Localização" width="250">
                            <h:outputText value="Logradouro #{item.enderecoImovel.nomeclog eq null or item.enderecoImovel.nomeclog eq '' ? item.enderecoImovel.logradouro : item.enderecoImovel.nomeclog}, Nº #{item.enderecoImovel.numero}" />
                        </p:column>
                        <p:column headerText="Bairro">  
                            <h:outputText value="#{item.enderecoImovel.bairro}"/>
                        </p:column> 
                        <p:column headerText="Proprietário" width="450" style="white-space: pre-wrap;">  
                            <h:outputText style="#{managerPesquisarImovel.proprietarios(item) eq '' ? 'color: red;' : ''}"
                                          value="#{managerPesquisarImovel.proprietarios(item) eq '' ? 'Proprietário Pendente' : managerPesquisarImovel.proprietarios(item)}"/>
                        </p:column> 
                    </p:dataTable> 


                   
                </p:panel>

              
            </h:form>
        </ui:define>
    </ui:composition>
</html>
